package com.fhz.recyclerviewtest.concatadapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.fhz.recyclerviewtest.R

/**
 * 时间:2023/5/10
 * @author Mr.Feng
 * 简述: TODO
 */
class ButtonAdapter(private val context: Context, private val headList: ArrayList<String>) :
    RecyclerView.Adapter<ButtonAdapter.ButtonViewHolder>() {

    inner class ButtonViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val text = itemView.findViewById<TextView>(R.id.tv_text)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ButtonViewHolder {
        val head = LayoutInflater.from(context).inflate(R.layout.item_head, parent, false)
        return ButtonViewHolder(head)
    }

    override fun onBindViewHolder(holder: ButtonViewHolder, position: Int) {
        holder.text.text = headList[position]
        holder.text.setBackgroundColor(ContextCompat.getColor(context,android.R.color.holo_red_light))
    }

    override fun getItemCount() = headList.size
}